﻿/*
* 
*
* 功 能： N/A
* 类 名： BDDATESOURSE
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDDATESOURSE
	/// </summary>
	public partial class BDDATESOURSEDAL:IBDDATESOURSE
	{
        public BDDATESOURSEDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDDATESOURSE");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}
        public bool Exists_idDate(string wellid, DateTime kssj)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from BDDATESOURSE");
            strSql.Append(" where WELLID=:wellid and KSSJ= to_date( ':kssj','yyyy-MM-dd HH24:mi:ss ')");
            OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22),
                    new OracleParameter(":KSSJ", OracleType.DateTime)
           
             };
            parameters[0].Value = wellid;
            parameters[1].Value = kssj;

            return DbHelperOra.Exists(strSql.ToString(), parameters);
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDDATESOURCEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDDATESOURSE(");
			strSql.Append("ID,WELLID,JCRQ,KSSJ,JSSJ,CJZSJ,CJPL,CJZDS,SCCDS,XCCDS,PULLID,DJID,PDGID,GLDW,JCDW,CSR,CJSBXH,CJSBBB,SCRJBB,CJSJ)");
			strSql.Append(" values (");
			strSql.Append("HTDZ_ID.nextval,:WELLID,:JCRQ,:KSSJ,:JSSJ,:CJZSJ,:CJPL,:CJZDS,:SCCDS,:XCCDS,:PULLID,:DJID,:PDGID,:GLDW,:JCDW,:CSR,:CJSBXH,:CJSBBB,:SCRJBB,:CJSJ)");
            OracleParameter[] parameters = {
                   
                    new OracleParameter(":WELLID", OracleType.VarChar,30),
                    new OracleParameter(":JCRQ", OracleType.DateTime),
                    new OracleParameter(":KSSJ", OracleType.DateTime),
                    new OracleParameter(":JSSJ", OracleType.DateTime),
                    new OracleParameter(":CJZSJ", OracleType.VarChar,30),
                    new OracleParameter(":CJPL", OracleType.Float,22),
                    new OracleParameter(":CJZDS", OracleType.Number,4),
                    new OracleParameter(":SCCDS", OracleType.Number,4),
                    new OracleParameter(":XCCDS", OracleType.Number,4),
                    new OracleParameter(":PULLID", OracleType.Number,18),
                    new OracleParameter(":DJID", OracleType.Number,18),
                    new OracleParameter(":PDGID", OracleType.Number,18),
                    new OracleParameter(":GLDW", OracleType.VarChar,30),
                    new OracleParameter(":JCDW", OracleType.VarChar,30),
                    new OracleParameter(":CSR", OracleType.VarChar,30),
                    new OracleParameter(":CJSBXH", OracleType.VarChar,30),
                    new OracleParameter(":CJSBBB", OracleType.VarChar,30),
                    new OracleParameter(":SCRJBB", OracleType.VarChar,30),
                    new OracleParameter(":CJSJ", OracleType.Blob)};

            
            parameters[0].Value = model.WELLID;
            parameters[1].Value = model.JCRQ;
            parameters[2].Value = model.KSSJ;
            parameters[3].Value = model.JSSJ;
            parameters[4].Value = model.CJZSJ;
            parameters[5].Value = model.CJPL;
            parameters[6].Value = model.CJZDS;
            parameters[7].Value = model.SCCDS;
            parameters[8].Value = model.XCCDS;
            parameters[9].Value = model.PULLID;
            parameters[10].Value = model.DJID;
            parameters[11].Value = model.PDGID;
            parameters[12].Value = model.GLDW;
            parameters[13].Value = model.JCDW;
            parameters[14].Value = model.CSR;
            parameters[15].Value = model.CJSBXH;
            parameters[16].Value = model.CJSBBB;
            parameters[17].Value = model.SCRJBB;
            parameters[18].Value = model.CJSJ;

           
			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDDATESOURCEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDDATESOURSE set ");
			strSql.Append("WELLID=:WELLID,");
			strSql.Append("JCRQ=:JCRQ,");
			strSql.Append("KSSJ=:KSSJ,");
			strSql.Append("JSSJ=:JSSJ,");
			strSql.Append("CJPL=:CJPL,");
			strSql.Append("CJZDS=:CJZDS,");
			strSql.Append("SCCDS=:SCCDS,");
			strSql.Append("XCCDS=:XCCDS,");
			strSql.Append("PULLID=:PULLID,");
			strSql.Append("DJID=:DJID,");
			strSql.Append("PDGID=:PDGID,");
			strSql.Append("GLDW=:GLDW,");
			strSql.Append("JCDW=:JCDW,");
			strSql.Append("CSR=:CSR,");
			strSql.Append("CJSBXH=:CJSBXH,");
			strSql.Append("CJSBBB=:CJSBBB,");
			strSql.Append("SCRJBB=:SCRJBB,");
			strSql.Append("CJSJ=:CJSJ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
                    
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":JCRQ", OracleType.DateTime),
					new OracleParameter(":KSSJ", OracleType.DateTime),
					new OracleParameter(":JSSJ", OracleType.DateTime),
					new OracleParameter(":CJPL", OracleType.Float,22),
					new OracleParameter(":CJZDS", OracleType.Number,4),
					new OracleParameter(":SCCDS", OracleType.Number,4),
					new OracleParameter(":XCCDS", OracleType.Number,4),
					new OracleParameter(":PULLID", OracleType.Number,18),
					new OracleParameter(":DJID", OracleType.Number,18),
					new OracleParameter(":PDGID", OracleType.Number,18),
					new OracleParameter(":GLDW", OracleType.VarChar,30),
					new OracleParameter(":JCDW", OracleType.VarChar,30),
					new OracleParameter(":CSR", OracleType.VarChar,30),
					new OracleParameter(":CJSBXH", OracleType.VarChar,30),
					new OracleParameter(":CJSBBB", OracleType.VarChar,30),
					new OracleParameter(":SCRJBB", OracleType.VarChar,30),
					new OracleParameter(":CJSJ", OracleType.Blob),
					new OracleParameter(":ID", OracleType.Number,18)};
			parameters[0].Value = model.WELLID;
			parameters[1].Value = model.JCRQ;
			parameters[2].Value = model.KSSJ;
			parameters[3].Value = model.JSSJ;
			parameters[4].Value = model.CJPL;
			parameters[5].Value = model.CJZDS;
			parameters[6].Value = model.SCCDS;
			parameters[7].Value = model.XCCDS;
			parameters[8].Value = model.PULLID;
			parameters[9].Value = model.DJID;
			parameters[10].Value = model.PDGID;
			parameters[11].Value = model.GLDW;
			parameters[12].Value = model.JCDW;
			parameters[13].Value = model.CSR;
			parameters[14].Value = model.CJSBXH;
			parameters[15].Value = model.CJSBBB;
			parameters[16].Value = model.SCRJBB;
			parameters[17].Value = model.CJSJ;
			parameters[18].Value = model.ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDATESOURSE ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDATESOURSE ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDDATESOURCEModel GetModel(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,JCRQ,KSSJ,JSSJ,CJPL,CJZDS,SCCDS,XCCDS,PULLID,DJID,PDGID,GLDW,JCDW,CSR,CJSBXH,CJSBBB,SCRJBB,CJSJ from BDDATESOURSE ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			BDDATESOURCEModel model=new BDDATESOURCEModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDDATESOURCEModel DataRowToModel(DataRow row)
		{
			BDDATESOURCEModel model=new BDDATESOURCEModel();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=decimal.Parse(row["ID"].ToString());
				}
				if(row["WELLID"]!=null)
				{
					model.WELLID=row["WELLID"].ToString();
				}
				if(row["JCRQ"]!=null && row["JCRQ"].ToString()!="")
				{
					model.JCRQ=DateTime.Parse(row["JCRQ"].ToString());
				}
				if(row["KSSJ"]!=null && row["KSSJ"].ToString()!="")
				{
					model.KSSJ=DateTime.Parse(row["KSSJ"].ToString());
				}
				if(row["JSSJ"]!=null && row["JSSJ"].ToString()!="")
				{
					model.JSSJ=DateTime.Parse(row["JSSJ"].ToString());
				}
				if(row["CJPL"]!=null && row["CJPL"].ToString()!="")
				{
					model.CJPL=decimal.Parse(row["CJPL"].ToString());
				}
				if(row["CJZDS"]!=null && row["CJZDS"].ToString()!="")
				{
					model.CJZDS=decimal.Parse(row["CJZDS"].ToString());
				}
				if(row["SCCDS"]!=null && row["SCCDS"].ToString()!="")
				{
					model.SCCDS=decimal.Parse(row["SCCDS"].ToString());
				}
				if(row["XCCDS"]!=null && row["XCCDS"].ToString()!="")
				{
					model.XCCDS=decimal.Parse(row["XCCDS"].ToString());
				}
				if(row["PULLID"]!=null && row["PULLID"].ToString()!="")
				{
					model.PULLID=decimal.Parse(row["PULLID"].ToString());
				}
				if(row["DJID"]!=null && row["DJID"].ToString()!="")
				{
					model.DJID=decimal.Parse(row["DJID"].ToString());
				}
				if(row["PDGID"]!=null && row["PDGID"].ToString()!="")
				{
					model.PDGID=decimal.Parse(row["PDGID"].ToString());
				}
				if(row["GLDW"]!=null)
				{
					model.GLDW=row["GLDW"].ToString();
				}
				if(row["JCDW"]!=null)
				{
					model.JCDW=row["JCDW"].ToString();
				}
				if(row["CSR"]!=null)
				{
					model.CSR=row["CSR"].ToString();
				}
				if(row["CJSBXH"]!=null)
				{
					model.CJSBXH=row["CJSBXH"].ToString();
				}
				if(row["CJSBBB"]!=null)
				{
					model.CJSBBB=row["CJSBBB"].ToString();
				}
				if(row["SCRJBB"]!=null)
				{
					model.SCRJBB=row["SCRJBB"].ToString();
				}
				if(row["CJSJ"]!=null && row["CJSJ"].ToString()!="")
				{
					model.CJSJ=(byte[])row["CJSJ"];
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,JCRQ,KSSJ,JSSJ,CJPL,CJZDS,SCCDS,XCCDS,PULLID,DJID,PDGID,GLDW,JCDW,CSR,CJSBXH,CJSBBB,SCRJBB,CJSJ ");
			strSql.Append(" FROM BDDATESOURSE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}
        /// <summary>
        /// 通过用户自定义SQL语句获得数据列表
        /// </summary>
        public DataSet GetList_SQL(string strsql)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(strsql);
            return DbHelperOra.Query(strSql.ToString());
        }

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDDATESOURSE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from BDDATESOURSE T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDDATESOURSE";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        /// <summary>
        /// 采用事务更新表数据
        /// </summary>
        /// <param name="dt">表数据</param>
        /// <param name="TableName">表名称</param>
        /// <returns></returns>
        public bool TransUpdateTable(DataTable dt)
        {
            return DbHelperOra.TransUpdateTable(dt,"BDDATESOURSE");
        }
		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

